<?

$menuEntry = "<?
session_start();

include_once(\"../classCol.php\");
include_once(\"../helpers/CHtml.php\");
include_once(\"../helpers/CJavascript.php\");
include_once(\"../models/GFetchers.php\");
include_once(\"../models/GHandlers.php\");
include_once(\"../models/GlobalHandlers.php\");
include_once(\"../models/GlobalFetchers.php\");
include_once(\"../helpers/Composer.php\");
include_once(\"../helpers/ComposerSourceDb.php\");

include_once(\"controllers/local.php\");
include_once(\"models/fetchers.php\");
include_once(\"models/handlers.php\");

\$thisMdl     = \"".$modulName."\";
\$modulNumber = \"".$menuNumber."\";

\$Misc        = new Misc;
\$GHtml       = new CGHtml;
\$GJs         = new CGJavascript;
\$CLFetchers  = new CLFetchers;
\$CLHandlers  = new CLHandlers;
\$CLocal      = new CLocal;

\$CFetchers   = new CGFetchers;
\$CHandlers   = new CGHandlers;

\$SourceDb   = new Composer;
\$SourceDb   = \$SourceDb->init(\"db\");

\$SourceDb->add(\"srcDbHdr\",      \"".$menuBodySrcDbHdr."\");
\$SourceDb->add(\"srcDbDtl\",      \"".$menuBodySrcDbDtl."\");
\$SourceDb->add(\"srcDbHdrLog\",   \"LOG_".$menuBodySrcDbHdr."\");
\$SourceDb->add(\"srcDbSequence\", \"MST_SEQUENCE\");

\$srcDb = \"".$menuMstUserId."\";

//check if the object of entry is exist if doesnt then create one
//First opening
if( !\$_POST[\"entry\"]    &&
    !\$_POST[\"addrow\"]   &&
    !\$_POST[\"confirm\"]  &&
    !\$_POST[\"back\"]     &&
    !\$_POST[\"droprow\"]  &&
    !\$_POST[\"view\"]     &&
    !\$_POST[\"cat_pick\"] ){

  /**
  * Reset the modify_mode
  *
  */
  \$_SESSION[\"modify_mode\"] = \"N\";

	/**
	* We dont have anything to Pick
	* so we are by pass the category pick
	*
	*/
	//require(\"entry_category_pick.php\");

	require(\"entry_data_body.php\");
}

/**
* if supplier picked then continue
*
*/
if(\$_POST[\"cat_pick\"]){

	require(\"entry_data_body.php\");
}

//if entry or confirm or back selected
if( \$_POST[\"entry\"]   ||
    \$_POST[\"confirm\"] ||
    \$_POST[\"back\"]    ){

	/**
	* check if the one has priviledge to entry
	*
	*/
	\$UID = unserialize(\$_SESSION[\"serUID\"]);

	if(\$UID->getPrivsByNumber( \$modulNumber, \"ENTRY_RIGHTS\") > 0){

		require(\"entry_details_check.php\");
	}else{

		\$Misc->usrError(\"Authed Error reason :\".\$chk_res.\" \");
	}
}

if(\$_POST[\"addrow\"]){

	require(\"entry_add_row.php\");
}

/**
* Presquities to use this item are:
*
* 1. to use dropBoxEntp[] auto numbering index
*    don't do it manually
* 2. The value of the dropBox should
*    take normal numbering instead of array numbering
*
*/
if(\$_POST[\"droprow\"]){

	//var_dump(\$_POST[\"dropBox\"]);

	/**
  * splice the dummy
  * The first 2 params are to shrink the array
  * e.g: array_splice(\$dummy, 2); is to shrink dummy to 2 elements
  *
  * The last 2 params is to concanate the array
  * it tells how many array to concat and the content of the array
  *
  * dropPoint needs to be reduce by 1 so we could have the cursor
  * of array for \$dummy at the correct posisition
  * e.g: dropPoint = 3, meaning the 3rd elements is going to be dust off
  *      so we only save the first and 2nd element. Then use splice
  *      to concat the 4th...nElement with the first 2 element.
  *
  */

	/**
	* get how many selected drops
	*
	*/
	\$dropTimes = sizeof(\$_POST[\"dropBox\"]);

	//usrDebug(\"dropTimes\",\$dropTimes);

	/**
	* Reupdate me please since
	* This code already built by MenuAccelerator
	*
	*/
	//list all records name
	\$lstArray = array(\"odrDateEnt\",
	                  \"odrRefEnt\",
	                  \"odrNoEnt\",
	                  \"catEnt\",
	                  \"grpEnt\",
	                  \"modelEnt\",
	                  \"unitEnt\",
	                  \"qtyEnt\",
	                  \"cvtEnt\",
	                  \"cvtQtyEnt\",
	                  \"recvQtyEnt\",
	                  \"priceEnt\",
	                  \"hrzTotEnt\");


	//shift it for many times
	foreach(\$lstArray as \$list){

		for(\$i = \$dropTimes ; \$i > 0 ; \$i--){

			/**
			* Since \$_POST[\"dropBox\"] index is using array numbering
			* then we need to reduce the droppoint by 1.
			* E.g: \$dropTimes = 3 => \$_POST[\"dropBox\"][3] will result Error
			*      since the dropTimes is trying to point to 3rd element
			*      of \$_POST[\"dropBox\"], which array wise is at [2] meaning 3rd element
			*
			*/
			\$dropPoint = \$_POST[\"dropBox\"][(\$i-1)];

			/**
			* slice it! so we could have the buffer's tail
			*
			*/
			\$bufTail   = array_slice(\$_POST[\$list], \$dropPoint);

			//var_dump(\$bufTail);

			//replace it
			array_splice(\$_POST[\$list],               /* The original array or dummy */
			            (\$dropPoint - ARRAY_NUMBER),  /* Calculate the cursor, since it comes with array numbering */
			            sizeof(\$bufTail),             /* The sizeof array concat with */
			            \$bufTail);                    /* The array we concat with */

			//var_dump(\$_POST[\$list]);
		}
	}
	unset(\$list);

	\$new_init_num = \$_SESSION[\"init_num\"] - \$dropTimes;
	//echo	\"<br/>\\$new_init_num :\".\$new_init_num ;
	if(\$new_init_num >= 0)

		\$_SESSION[\"init_num\"] = \$new_init_num;
	else

		\$_SESSION[\"init_num\"] = 0;

	require(\"entry_restore_me.php\");
}

echo \"<br/><br/><br/><br/>\";
?> ";

?>
